#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = "lrj";

import re;
# from base import python_base_02 as pb02;
from base.python_base2 import *;

'''
python 基础练习
'''

# ======== 模块调用 ========
def fun_10():
    # pb02.fun_01();
    print(User("hj", 22, "hj@163.com").__dict__);

# ======== 异常处理用 ========
def fun_11():
    try:
        for i in list(range(1, 10)):
            print(i);
        a = 1 / 1;
    except BaseException as be:
        print(be);
    finally:
        print("必须执行的代码块");

# ======== 文件读写 ========
def fun_12():
    f = open(file="D:/temp/text.txt", mode="w", encoding="utf-8");
    f.writelines(["cdacda", "\n", "cadscdasdc", "\n", "传达出大事传达室成都市擦", "\n", "cdsacdsacdas"]);
    f.close();

def fun_13():
    f =None;
    try:
        f = open(file="D:/temp/text.txt", mode="r", encoding="utf-8");
        results = f.readlines();
        print(results);
    except BaseException as e:
        print(e);
    finally:
        if f:
            f.close();

def fun_14():
    with open(file="F:/temp/text.txt", mode="r", encoding="utf-8") as f:
        print(f.readlines());

def fun_15():
    with open(file="F:/temp/text.txt", mode="a", encoding="utf-8") as f:
        f.writelines(["追加第一行", "\n", "追加第二行", "\n", "追加第三行"]);

if __name__ == '__main__':
    fun_11();
    fun_15();




